import React, {useEffect, useState} from 'react';
import ReactECharts from 'echarts-for-react';
import {$getPostNum} from "../../api/Demoapi";

const BarChart= () => {
    const [data,setData]=useState([]);
    const [data1,setData1]=useState([]);
    const getPostNum=async ()=>{
        const response= await $getPostNum({long:'7'});
        console.log(response.data);
        // 提取日期
        const dates = Object.keys(response.data);
        setData(dates);
        // 提取数量
        const counts = Object.values(response.data);
        setData1(counts);
    }
    useEffect(()=>{
        getPostNum();
    },[])
    const option = {
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: data
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
                data:  data1,
                type: 'line',
                areaStyle: {}
            }
        ]
    };

    return <ReactECharts option={option} style={{ height: '400px' }} />;
};




export default BarChart;
